<template>
    <div>
        <div id="form">
            <van-nav-bar
                    style="position: fixed; width: 100%; top: 0;" title="返馈意见"
                    @click-left="onClickLeft" @click-right="onClickRight" right-text="保存" left-arrow
            />
            <div style="height: 1.02rem;"></div>
            <van-notice-bar
                    left-icon="volume-o"
                    text="返馈意见将以匿名的方式提交，欢迎全体员工提出你们的宝贵意见。"
            />
            <van-form @submit="onSubmit" ref="form">
                <van-cell-group title="">
                    <van-field
                            required v-model="item.content"
                            rows="2"
                            autosize
                            label="意见"
                            type="textarea"
                            maxlength="300"
                            placeholder="请输入对本公示的意见"
                            show-word-limit
                            :rules="[{ required: true, message: '请输入对本公示的意见' }]"
                    />
                </van-cell-group>
            </van-form>
        </div>
    </div>
</template>

<script>
    import {mapGetters} from 'vuex'
    import {Toast} from 'vant';
    import request from '@/utils/request'

    export default {
        name: "form",
        mixins: [window.mixins.clone],
        data() {
            return {
                item: {}
            }
        },
        computed: {
            ...mapGetters([
                'activity'
            ])
        },
        mounted() {

        },
        created() {
            this.$nextTick(() => {

            })
        },
        methods: {
            onSubmit() {
                this.item.activity = this.activity
                let tmp = this.$deepClone(this.item)
                Toast.loading({
                    duration: 0,
                    message: '提交中...',
                    forbidClick: true,
                });
                request({
                    url: '/api/activity_emp_elect_suggestion',
                    method: 'post',
                    data: tmp
                }).then(() => {
                    Toast.clear();
                    Toast('保存成功')
                    this.onClickLeft()
                }).catch(() => {
                    Toast.clear();
                    Toast('保存失败')
                })
            },
            onClickLeft() {
                if (window.history.length <= 1) {
                    this.$router.push({path: '/'})
                    return false
                } else {
                    this.back = true
                    this.$router.go(-1)
                }
            },
            onClickRight() {
                this.$refs.form.submit()
            }
        }
    }
</script>

<style scoped>

</style>